<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <!-- 只保留这1个表单组件！删掉下面重复的那个！ -->
    <cw-ysryqkmx-form
      ref="realForm"
      @ok="submitCallback"
      :disabled="disableSubmit"
      :scene="currentScene"
    />
  </j-modal>
</template>

<script>
import CwYsryqkmxForm from './CwYsryqkmxForm'
export default {
  name: 'CwYsryqkmxModal',
  components: { CwYsryqkmxForm },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      currentScene: 'edit' // 默认新增，避免默认edit导致的问题
    }
  },
  methods: {
    add() {
      this.currentScene = 'add';
      this.title = '新增预算人员情况';
      console.log('父组件add传递的scene：', this.currentScene);
      this.$nextTick(() => {
        this.visible = true;
        // 调用子组件新增方法（确保子组件初始化空表单）
        this.$refs.realForm && this.$refs.realForm.add();
      });
    },
    edit (record) {
      this.visible=true
      this.$nextTick(()=>{
        this.$refs.realForm.edit(record);
      })
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.currentScene = ''; // 仅关闭弹窗时重置，保证下次新增正常
    },
    handleOk() {
      this.$refs.realForm && this.$refs.realForm.submitForm();
    },
    submitCallback() {
      this.$emit('ok');
      this.visible = false;
      this.currentScene = ''; // 重置场景
    },
    handleCancel() {
      this.close();
    }
  }
}
</script>